/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.personInfo;

import model.Constants;

/**
 * Contains all information about person's name.
 * @author Dmitri Paziy
 */
public class Name implements Cloneable {

    private final String firstName;
    private final String lastName;

    /**
     * @param firstName First name of a person
     * @param lastName Last name of a person
     * @throws IllegalArgumentException if firstName or lastName were specified
     * as <i>null</i>.
     */
    public Name(String firstName, String lastName) {
        if (firstName == null || lastName == null) {
            throw new IllegalArgumentException(Constants.NULL_ARGUMENT_MESSAGE);
        }

        this.firstName = firstName;
        this.lastName = lastName;
    }

    /**
     * Getter of first name
     * @return first name
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Getter of last name
     * @return last name
     */
    public String getLastName() {
        return lastName;
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();

        builder.append("First name: ");
        builder.append(firstName);
        builder.append(Constants.LINE_SEPARATOR);
        builder.append("Last name: ");
        builder.append(lastName);
        builder.append(Constants.LINE_SEPARATOR);

        return builder.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Name other = (Name) obj;
        if ((this.firstName == null) ? (other.firstName != null) : !this.firstName.equals(other.firstName)) {
            return false;
        }
        if ((this.lastName == null) ? (other.lastName != null) : !this.lastName.equals(other.lastName)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + (this.firstName != null ? this.firstName.hashCode() : 0);
        hash = 53 * hash + (this.lastName != null ? this.lastName.hashCode() : 0);
        return hash;
    }

    @Override
    public Object clone() {
        return new Name(firstName, lastName);
    }
}
